<?php
	session_start();
	include("load-settings.php");

	$text = "";

	if(isset($_POST['email']))
	{

		$email = mysql_real_escape_string($_POST['email']);

		$result = mysql_query("SELECT * FROM user WHERE paypal = '$email'");

		if(mysql_num_rows($result) == 0)
			$text = "No user with that email address is registered.";
		else
		{
			$new_pass = substr(md5(rand()), 0, 7);
			$new_hash = crypt($new_pass);
			$row = mysql_fetch_array($result);

			mysql_query("UPDATE user SET password = '$new_hash' WHERE id = ".$row['id']);

			$to = $_POST['email'];
			$subject = 'Password reset';
			$message = 'Your new ELO Coach password is: '.$new_pass."\r\nPlease remember to change your password after logging in.";
			$headers = 'From: Admin@VeteranBoosters.com' . "\r\n" .
				'Reply-To: Admin@VeteranBoosters.com' . "\r\n" .
				'X-Mailer: PHP/' . phpversion();

			mail($to, $subject, $message, $headers);

			$text = "Your new password has been emailed to you.";
		}
	}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Veteran Boosters Order Tracking</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <link rel="stylesheet" href="css/font-awesome.css" />
    <link rel="stylesheet" href="css/unicorn-login.css" />
    <script type="text/javascript" src="js/respond.min.js"></script>

    <script src="javascripts/application.js" type="text/javascript"></script>
</head>    <body>
<div id="container">
    <div id="logo">
        <img src="img/logo.png" alt="" />
    </div>
    <div id="user" style="display: none !important;">
        <div class="avatar">
            <div class="inner"></div>
            <img src="img/demo/av1_1.jpg" />
        </div>
        <div class="text">
            <h4>Hello,<span class="user_name"></span></h4>
        </div>
    </div>
    <div id="loginbox">

        <form  method="post">
            <p>Reset password</p>
            <div class="input-group input-sm">
                <span class="input-group-addon"><i class="fa fa-user"></i></span>
                <input class="form-control" type="email" id="email" placeholder="Email" name="email" />
            </div>
            <div class="form-actions clearfix">
                <button type="submit" class="btn btn-block btn-primary btn-default" value=" password reset" >Send</button>
                <button style="margin-top: 10px;" type="button" class="btn btn-success pull-left" onclick="window.location.href='login.php'">
                    Login <i class="icon-signin"></i>
                </button>
            </div>
            <div class="row-fluid">
	        <span><?php echo $text; ?></span>

            </div>


        </form>

    </div>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.custom.min.js"></script>

<script src="js/unicorn.login.js"></script>
</body>
</html>
